package com.kpmg.datalake.web.controller;


import com.kpmg.datalake.common.controller.BaseController;
import com.kpmg.datalake.common.service.CommonExecuteService;
import com.kpmg.datalake.common.vo.ServerResponse;
import java.util.ArrayList;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author azhao6
 * @since 2018-08-16
 */
@RestController
@RequestMapping("/comDictType")
public class ComDictTypeController extends BaseController {

  @Resource
  private CommonExecuteService commonExecuteService;

  /**
   * 通用信息处理
   *
   * @param projectId 项目信息
   * @param data 处理数据
   * @return ServerResponse
   */
  @PostMapping("getCommonInfo")
  public ServerResponse<ArrayList<Map<String, Object>>> getCommonInfo(
      @Param("projectId") String projectId, @Param("data") String data) {
    try {
      return super
          .doSuccess(new ArrayList<>(commonExecuteService.queryListByString(projectId, data)));
    } catch (Exception e) {
      return super.doError(e);
    }
  }

  /**
   * 通用信息处理
   *
   * @param projectId 项目信息
   * @param data 处理数据
   * @return ServerResponse
   */
  @PostMapping("handlerCommonInfo")
  public ServerResponse<Integer> handlerCommonInfo(
      @Param("projectId") String projectId, @Param("data") String data) {
    try {
      return super.doSuccess(commonExecuteService.updateByString(projectId, data));
    } catch (Exception e) {
      return super.doError(e);
    }
  }

}

